/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sdd.facades.factories;

import com.sdd.entities.OrderItem;
import com.sdd.plains.CartItem;
import com.sdd.plains.ProductPlain;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

/**
 *
 * @author Fernando
 */
@LocalBean
@Stateless
public class OrderItemFactoryFacadeBean {
    @EJB
    ProductFactoryFacadeBean productFactoryFacadeBean;
    
    public CartItem createCartItem(OrderItem orderItem) {
        if(orderItem == null) return null;
        ProductPlain product = productFactoryFacadeBean.createProductPlain(orderItem.getProduct());
        CartItem cartItem = new CartItem(product);
        cartItem.setQuantity(orderItem.getQty());
        return cartItem;
    } 
    
    public List<CartItem> createCartItems(List<OrderItem> list) {
        if(list == null) return null;
        ArrayList<CartItem> newList = new ArrayList<CartItem>();
        Iterator<OrderItem> it = list.iterator();
        while(it.hasNext()) {
            newList.add(createCartItem(it.next()));
        }
        return newList;
    }
}
